﻿using ContactSMS.UseCases.PluginInterfaces;
using ContactCoreBusiness = ContactSMS.CoreBusiness.Contact;

namespace ContactSMS.Plugins.DataStore.InMemory
{
    public class ContactInMemoryRepository : IContactRepository
    {
        public static List<ContactCoreBusiness> _contactList;

        public ContactInMemoryRepository()
        {

        }

        public async Task<List<ContactCoreBusiness>> GetContactsAsync(string filterText)
        {
            // 在这里进行异步操作，例如从数据库或网络获取联系人列表
            List<ContactCoreBusiness> contacts = new List<ContactCoreBusiness>();

            for (int i = 0; i < 20; i++)
            {
                var contact = new ContactCoreBusiness()
                {
                    Id = i,
                    Name = "小许" + i.ToString(),
                    Avatar = ""
                };
                contacts.Add(contact);
            }

            // 如果有筛选文本，则进行筛选操作
            if (!string.IsNullOrEmpty(filterText))
            {
                contacts = contacts.Where(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToLower().Contains(filterText)).ToList();
            }

            // 等待异步操作完成，并返回联系人列表
            await Task.Delay(100); // 模拟异步操作
            return contacts;
        }
    }
}
